import { createRouter, createWebHistory } from "vue-router";

const routerHistory = createWebHistory();

import Home from "@/views/Home.vue";

import Layout from "@/views/layout.vue";

const routes = [
  {
    path: "/",
    name: "HomeSy",
    redirect: "/home",
  },
];

const routes1 = [
  {
    path: "/home", //首页
    name: "Home",
    component: Layout,
    redirect: "/home/index",
    children: [
      {
        path: "index",
        name: "Home",
        component: Home,
        meta: {
          title: "首页",
        },
      },
    ],
  },
  {
    path: "/num", //数字滚动
    name: "Num",
    component: Layout,
    redirect: "/num/index",
    children: [
      {
        path: "index",
        name: "Num",
        component: () =>
          import(/* webpackChunkName: "page" */ "@/views/num.vue"),
        meta: {
          title: "数字滚动",
        },
      },
    ],
  },
  {
    path: "/gsap", //数字滚动
    name: "Gsap",
    component: Layout,
    redirect: "/gsap/index",
    children: [
      {
        path: "index",
        name: "Gsap",
        component: () =>
          import(/* webpackChunkName: "page" */ "@/views/gsap.vue"),
        meta: {
          title: "gsap动画",
        },
      },
    ],
  },
];

const router = createRouter({
  history: routerHistory,
  routes,
});

router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title;
  }

  next();
});

routes1.forEach((route) => {
  router.addRoute(route);
});

export default router;
